﻿using System;
using System.Collections.Generic;
using System.Globalization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using JTLeigh.Commerce.Spencer.Features.ProductImages.Common.Entities;
using JTLeigh.Commerce.Spencer.Core.Testing;

namespace JTLeigh.Commerce.Spencer.Features.ProductImages.Common.UnitTests.Entities
{

	/// <summary>
	/// Unit tests for the <see cref="LocalizedProductImage"/> class.
	/// </summary>
	[TestClass]
	public class LocalizedProductImageFixture
	{

		#region Methods

		/// <summary>
		/// Ensures <see cref="LocalizedProductImage"/> returns localized values for its 
		/// localizable fields when its constructor is passed a <see cref="ProductImageLocalization"/> 
		/// object.
		/// </summary>
		[TestMethod]
		public void TestLocalizedProductImageOperationWithLocalization()
		{
			ProductImage image;
			ProductImageLocalization localization;
			LocalizedProductImage localizedImage;

			image = new ProductImage
			{
				ImageId = Guid.NewGuid(),
				ViewId = Guid.NewGuid(),
				DefaultAlternativeText = "defaultAlternativeText",
				DefaultUsagePermissionText = "defaultUsagePermissionText",
			};
			localization = new ProductImageLocalization
			{
				ImageId = Guid.NewGuid(),
				CultureId = TestConstants.CultureId.EnglishCanada,
				AlternativeText = "localizedAlternativeText",
				UsagePermissionText = "localizedUsagePermissionText",
			};
			localizedImage = new LocalizedProductImage(image, localization);

			Assert.AreEqual(image.ImageId, localizedImage.ImageId);
			Assert.AreEqual(image.ViewId, localizedImage.ViewId);
			Assert.AreSame(image.Variants, localizedImage.Variants);
			Assert.AreEqual(localization.AlternativeText, localizedImage.AlternativeText);
			Assert.AreEqual(localization.UsagePermissionText, localizedImage.UsagePermissionText);
		}

		/// <summary>
		/// Ensures <see cref="LocalizedProductImage"/> returns default values for its localizable 
		/// fields when its constructor is passed a <see langword="null"/> value instead of a 
		/// <see cref="ProductImageLocalization"/> object.
		/// </summary>
		[TestMethod]
		public void TestLocalizedProductImageOperationWithoutLocalization()
		{
			ProductImage image;
			LocalizedProductImage localizedImage;

			image = new ProductImage
			{
				ImageId = Guid.NewGuid(),
				ViewId = Guid.NewGuid(),
				DefaultAlternativeText = "defaultAlternativeText",
				DefaultUsagePermissionText = "defaultUsagePermissionText",
			};
			localizedImage = new LocalizedProductImage(image, null);

			Assert.AreEqual(image.ImageId, localizedImage.ImageId);
			Assert.AreEqual(image.ViewId, localizedImage.ViewId);
			Assert.AreSame(image.Variants, localizedImage.Variants);
			Assert.AreEqual(image.DefaultAlternativeText, localizedImage.AlternativeText);
			Assert.AreEqual(image.DefaultUsagePermissionText, localizedImage.UsagePermissionText);
		}

		#endregion // Methods

	}

}
